<?php
/**
 * 根据不同类型显示文章列表
 * 使用方法
 * 按分类：  
 * {:W('ArticleList',array('type'=>'category',catid=>'5',thumb='0','listRows'=>'5','tpl'=>'index'))}
 * 按推荐位：  
 * {:W('ArticleList',array('type'=>'flag',flag=>'index',thumb='0',catid=>'5','listRows'=>'5','tpl'=>'index'))}
 * 随机：  
 * {:W('ArticleList',array('type'=>'random','listRows'=>'5','tpl'=>'index'))}
 */
class ArticleListWidget extends Widget {
    public function render($data) 
    {
    	$data['listRows']=isset($data['listRows'])?$data['listRows']:5;
    	$data['tpl']=isset($data['tpl'])?$data['tpl']:'index';
    	$article=D('Article');
    	switch($data['type'])
    	{
    		case 'category':
    			$data['articles']=$article->getArticleListByCategory($data['catid'],$data['thumb'],$data['listRows']);
    		break;
    		case 'flag':
    			$data['articles']=$article->getArticleListByFlag($data['flag'],$data['thumb'],$data['catid'],$data['listRows']);
    		break;
    		case 'random':
    			$data['articles']=$article->getArticleListByRandom($data['listRows']);
    		break;
            case 'hot':
                $data['articles']=$article->getArticleListByMap('',$data['listRows'],0,'hit DESC');
            break;
            case 'like':
                $where['category_id']=$data['catid'];
                $where['id']=array('neq',$data['currentId']);
                $data['articles']=$article->getArticleListByMap($where,$data['listRows'],0,'id DESC');
            break;    		
    	}
    	$html = $this->renderFile($data['tpl'],$data);
		return $html;
    }
}
?>
